/**
 * 
 */
package com.p2p.front.dal.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.front.dal.model.TenderAutoQueue;

/**
 * @author ruiqi
 *
 */
public interface TenderAutoQueueDao extends BaseMapper{

	@Insert("insert p2p_tender_auto_queue(USER_ID,RANK)values(#{userId},#{rank})")
	public void create(TenderAutoQueue tenderAutoQueue);
	
	@Update("update p2p_tender_auto_queue set RANK=#{rank} where USER_ID=#{userId}")
	public int updateRank(TenderAutoQueue tenderAutoQueue);
	
	@Update("update p2p_tender_auto_queue set RANK=null")
	public int cleanRank();
	
	@Delete("delete FROM p2p_tender_auto_queue where USER_ID=#{userId}")
	public int remove(String userId);
	
	@Select("select ID,USER_ID,RANK FROM p2p_tender_auto_queue")
	@ResultMap("TenderAutoQueueResultMap")
	public List<TenderAutoQueue> listAll();

	@Select("select ID,USER_ID,RANK FROM p2p_tender_auto_queue where USER_ID=#{userId}")
	@ResultMap("TenderAutoQueueResultMap")
	public TenderAutoQueue getByUserId(String userId);
	
	@Select("select count(ID) from p2p_tender_auto_queue")
	public Integer getMaxRank();

	@Select("select count(*) from p2p_tender_auto_queue p where p.id<=#{id}")
	public Integer getRankById(String id);
	//public void replaceRank(List<TenderAutoQueue> list);
}
